<?php

namespace App\Http\Middleware;

use App\Models\Category;
use App\Models\Channel;
use App\Models\Partner;
use Closure;

class HomeChannel
{
    public function handle($request, Closure $next)
    {
        view()->share('channels',$this->getChannels());
//        view()->share('cates',$this->getCategory());
//        view()->share('partners',$this->getPartner());
        return $next($request);
    }

    protected function getChannels(){
        $menus = Channel::orderBy('sort', 'asc')->get(['id','name','link','target'])->toArray();
        return $menus;

    }

//    protected function getPartner(){
//        $partners = Partner::where('status',Partner::STATUS_1)->orderBy('sort', 'asc')->get(['id','title','link','target'])->toArray();
//        return $partners;
//
//    }

    protected function getCategory(){
        $cates = Category::where('status',Category::STATUS_1)->orderBy('sort', 'asc')->get(['id','name'])->toArray();
//        $cates = array_chunk($cates,5);
//        dump($cates);
        return $cates;
    }
}
